<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>用户个人信息修改</span>
      </div>
      <div>
        <div style="height: 350px;overflow-y: auto;overflow-x: hidden;">
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm"  size="small" label-width="100px" class="demo-ruleForm">
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="用户名称">
                <el-input v-model="ruleForm.name" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="性别">
                <el-radio-group v-model="ruleForm.gender">
                  <el-radio label="男"></el-radio>
                  <el-radio label="女"></el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="出生日期">
                <el-date-picker
                  v-model="ruleForm.birthday"
                  type="date"
                  value-format="yyyyMMdd"
                  @change="birthdayTime"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="移动电话">
                <el-input v-model="ruleForm.mobilePhone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="固定电话">
                <el-input v-model="ruleForm.telephone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="电子邮件">
                <el-input v-model="ruleForm.email"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="家庭电话">
                <el-input v-model="ruleForm.homePhone"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="传真号码">
                <el-input v-model="ruleForm.faxno"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="QQ号">
                <el-input v-model="ruleForm.qq"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="微信号">
                <el-input v-model="ruleForm.wechat"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="微博号">
                <el-input v-model="ruleForm.microBlog"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="联系地址">
                <el-input v-model="ruleForm.address"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="邮政编码">
                <el-input v-model="ruleForm.zipCode"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="办公地点">
                <el-input v-model="ruleForm.office"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="身份证号">
                <el-input v-model="ruleForm.cardId"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="参加工作日期">
                <el-date-picker
                  v-model="ruleForm.workDate"
                  type="date"
                  value-format="yyyyMMdd"
                  @change="workDateTime"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="入职日期">
                <el-date-picker
                  v-model="ruleForm.employedDate"
                  type="date"
                  value-format="yyyyMMdd"
                  @change="employedDateTime"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="工作证号码">
                <el-input v-model="ruleForm.employerId"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="政治面貌">
                <el-select v-model="ruleForm.politicalStatus" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.codeValue"
                    :label="item.codeName"
                    :value="item.codeValue">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="5">
            <el-col :span="12">
              <el-form-item label="备注信息">
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="ruleForm.remarks">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        </div>
        <div style="margin-top: 15px;">
          <el-row :gutter="5">
            <el-col style="text-align: right;">
              <el-button class="filter-item" type="primary" @click="saveData">确认修改</el-button>
              <el-button class="filter-item" type="primary" @click="closeSelf">关 闭</el-button>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'changePassword',
  data() {
    return {
      options: [],
      formData: {},
      politicsList: {
        condition: [
          {
            property: 'codeType',
            value: 'USER_POLITICAL_STATUS',
            type: 'EQ'
          }
        ]
      },
      postlist: {
        userId: ''
      },
      ruleForm: {
        gender: '',
        birthday: '',
        mobilePhone: '',
        telephone: '',
        email: '',
        homePhone: '',
        faxno: '',
        qq: '',
        wechat: '',
        microBlog: '',
        address: '',
        zipCode: '',
        office: '',
        cardId: '',
        workDate: '',
        employedDate: '',
        employerId: '',
        politicalStatus: '',
        remarks: ''
      },
      rules: {
        // mobilePhone: [
        //   { min: 11, max: 11, message: '请输入11位手机号', trigger: 'blur' }
        // ],
        // telephone: [
        //   { min: 11, max: 11, message: '请输入11位电话号', trigger: 'blur' }
        // ]
      }
    }
  },
  mounted() {
    this.fetchData()
    this.politicsData()
  },
  methods: {
    fetchData() {
      this.$store
        .dispatch('UserInfo', this.postlist)
        .then(res => {
          this.ruleForm = res.data
          this.ruleForm.birthday = res.data.birthday.substring(0, 8)
          this.ruleForm.workDate = res.data.workDate.substring(0, 8)
          this.ruleForm.employedDate = res.data.employedDate.substring(0, 8)
        })
        .catch(() => {

        })
    },
    politicsData() {
      this.$store
        .dispatch('PoliticsGetCodeList', this.politicsList)
        .then(res => {
          this.options = res.data.records
        })
        .catch(() => {

        })
    },
    closeSelf() {
      this.$router.push({ name: 'Dashboard' })
    },
    saveData() {
      this.formData = this.ruleForm
      if (this.ruleForm.birthday != null) {
        this.ruleForm.birthday = this.ruleForm.birthday + '000000'
      } else {
        this.ruleForm.birthday = null
      }
      if (this.ruleForm.workDate != null) {
        this.ruleForm.workDate = this.ruleForm.workDate + '000000'
      } else {
        this.ruleForm.workDate = null
      }
      if (this.ruleForm.employedDate != null) {
        this.ruleForm.employedDate = this.ruleForm.employedDate + '000000'
      } else {
        this.ruleForm.employedDate = null
      }
      this.$store
        .dispatch('UserInfoChange', this.formData)
        .then(res => {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
        })
        .catch(() => {

        })
    },
    birthdayTime(val) {
      // this.ruleForm.birthday = val + '000000'
    },
    workDateTime(val) {
      // this.ruleForm.workDate = val + '000000'
    },
    employedDateTime(val) {
      // this.ruleForm.employedDate = val + '000000'
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
